Telegram Group & Telegram Channel
Sorts one list based on another list containing the desired indexes.

Use zip() and sorted() to combine and sort the two lists, based on the values of indexes. Use a list comprehension to get the first element of each pair from the result.

Code:

def sort_by_indexes(lst, indexes):
return [val for _, val in sorted(zip(indexes, lst), key = lambda x: x[0])]

EXAMPLES

a = ['eggs', 'bread', 'oranges', 'jam', 'apples', 'milk']
b = [3, 2, 6, 4, 1, 5]
sort_by_indexes(a, b) # ['apples', 'bread', 'eggs', 'jam', 'milk', 'oranges']


Share and Support @python_codes



tg-me.com/python_codes/134
Create:
Last Update:

Sorts one list based on another list containing the desired indexes.

Use zip() and sorted() to combine and sort the two lists, based on the values of indexes. Use a list comprehension to get the first element of each pair from the result.

Code:

def sort_by_indexes(lst, indexes):
return [val for _, val in sorted(zip(indexes, lst), key = lambda x: x[0])]

EXAMPLES

a = ['eggs', 'bread', 'oranges', 'jam', 'apples', 'milk']
b = [3, 2, 6, 4, 1, 5]
sort_by_indexes(a, b) # ['apples', 'bread', 'eggs', 'jam', 'milk', 'oranges']


Share and Support @python_codes

BY Python Codes


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python_codes/134

View MORE
Open in Telegram


Python Codes Telegram | DID YOU KNOW?

Date: |

Unlimited members in Telegram group now

Telegram has made it easier for its users to communicate, as it has introduced a feature that allows more than 200,000 users in a group chat. However, if the users in a group chat move past 200,000, it changes into "Broadcast Group", but the feature comes with a restriction. Groups with close to 200k members can be converted to a Broadcast Group that allows unlimited members. Only admins can post in Broadcast Groups, but everyone can read along and participate in group Voice Chats," Telegram added.

The global forecast for the Asian markets is murky following recent volatility, with crude oil prices providing support in what has been an otherwise tough month. The European markets were down and the U.S. bourses were mixed and flat and the Asian markets figure to split the difference.The TSE finished modestly lower on Friday following losses from the financial shares and property stocks.For the day, the index sank 15.09 points or 0.49 percent to finish at 3,061.35 after trading between 3,057.84 and 3,089.78. Volume was 1.39 billion shares worth 1.30 billion Singapore dollars. There were 285 decliners and 184 gainers.

Python Codes from no


Telegram Python Codes
FROM USA